﻿namespace ufida.u9.ait.openapi
{
	using System;
	using System.Collections.Generic;
	using System.Text;
    using ufida.u9.ait.openapi.utils;
    using UFIDA.U9.AR.Receival;
    using UFIDA.U9.CBO.Pub.Controller;
    using UFSoft.UBF.AopFrame;	
	using UFSoft.UBF.Util.Context;

	/// <summary>
	/// RecBillApproveSV partial 
	/// </summary>	
	public partial class RecBillApproveSV 
	{	
		internal BaseStrategy Select()
		{
			return new RecBillApproveSVImpementStrategy();	
		}		
	}
	
	#region  implement strategy	
	/// <summary>
	/// Impement Implement
	/// 
	/// </summary>	
	internal partial class RecBillApproveSVImpementStrategy : BaseStrategy
	{
		public RecBillApproveSVImpementStrategy() { }

		public override object Do(object obj)
		{						
			RecBillApproveSV bpObj = (RecBillApproveSV)obj;

            try
            {
                if (bpObj.Data == null || bpObj.Data.Count == 0)
                    throw new Exception("传入参数为空");
                List<CommonArchiveDataDTOData> retlist = new List<CommonArchiveDataDTOData>();

                foreach (var dto in bpObj.Data)
                {
                    if (String.IsNullOrEmpty(dto.DocNo))
                        throw new Exception("必须传入单号[DocNo]");

                    RecBillHead doc = RecBillHead.Finder.Find($"DocNo='{dto.DocNo}'");
                    if (doc == null)
                    {
						throw new Exception($"单号:{dto.DocNo}不存在");
                    }
                    else
                    {
                        //修改逻辑
                        doc = RecBillBase.ApproveDoc(doc);
                        retlist.Add(new CommonArchiveDataDTOData() { Code = doc.DocNo });
                    }
                }

                return ResultUtils.success(bpObj, bpObj.Data, retlist);
            }
            catch (Exception ex)
            {
                //DeleteDoc(bpObj.Data);
                return ResultUtils.error(bpObj, bpObj.Data, ex);
            }
        }		
	}

	#endregion
	
	
}